<template>
  <span
    class="title-badge"
    :class="[
      tierClass,
      sizeClass,
      variantClass,
      { active, clickable }
    ]"
    @click="handleClick"
    :title="tooltipText"
  >
    <span class="title-text">{{ title || '未命名称号' }}</span>
  </span>
  
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  title: { type: String, default: '' },
  // 用户当前等级或该称号的解锁等级
  level: { type: Number, default: 1 },
  // 尺寸：sm | md | lg | xl
  size: { type: String, default: 'md' },
  // 当前是否正在使用该称号
  active: { type: Boolean, default: false },
  // 是否可点击
  clickable: { type: Boolean, default: false },
  // 视觉风格：auto(随等级) | neon(红色霓虹酷炫) | aurora(极光虹彩)
  variant: { type: String, default: 'auto' }
})

const emit = defineEmits(['click'])

// 称号名称 → 样式档位映射（与称号管理一致）
const tierByTitle = {
  '墨痕初绽': 1,
  '玄疆漫步': 2,
  '万象染境': 3,
  '永夜封疆': 4,
  '无界墨尊': 5
}

const getTierFromLevel = (level) => {
  if (level >= 20) return 5
  if (level >= 15) return 4
  if (level >= 10) return 3
  if (level >= 5) return 2
  return 1
}

// 首选根据称号名称确定样式，其次按等级回退
const tier = computed(() => {
  const name = (props.title || '').trim()
  if (name && tierByTitle[name]) return tierByTitle[name]
  return getTierFromLevel(Number(props.level) || 1)
})

const tierClass = computed(() => `tier-${tier.value}`)

const neonColorByTier = (tierNum) => {
  switch (tierNum) {
    case 1: return 'neon-blue'
    case 2: return 'neon-green'
    case 3: return 'neon-purple'
    case 4: return 'neon-cyan'
    case 5: return 'neon-red'
    default: return 'neon-blue'
  }
}

const variantClass = computed(() => {
  const v = (props.variant || 'auto').toLowerCase()
  // 关闭霓虹，默认采用按等级的层级动画（tier-1..5 已内建）
  if (v === 'auto' || v === 'none' || v === 'clean') return null
  if (v === 'neon') return ['variant-neon', neonColorByTier(tier.value)]
  if (v === 'aurora') return 'variant-aurora'
  return null
})

const sizeClass = computed(() => {
  const s = (props.size || 'md').toLowerCase()
  return {
    sm: 'size-sm',
    md: 'size-md',
    lg: 'size-lg',
    xl: 'size-xl'
  }[s] || 'size-md'
})

const tooltipText = computed(() => {
  const t = props.title || '称号'
  return `${t} · LV.${props.level}`
})

const handleClick = (e) => {
  if (props.clickable) emit('click', e)
}
</script>

<style scoped>
/* 基础样式 */
.title-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 4px 10px;
  border-radius: 999px;
  position: relative;
  user-select: none;
  white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.06);
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  backface-visibility: hidden;
  transform: translateZ(0); /* 减少子像素模糊 */
}

.title-badge .title-text {
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
  position: relative;
  z-index: 1;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.title-badge.active {
  box-shadow: 0 6px 18px rgba(59,130,246,0.25);
}

.title-badge.clickable {
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.title-badge.clickable:hover { transform: translateY(-1px); }

/* 尺寸 */
.size-sm { font-size: 12px; padding: 3px 8px; }
.size-md { font-size: 14px; padding: 4px 10px; }
.size-lg { font-size: 16px; padding: 6px 12px; }
.size-xl { font-size: 18px; padding: 8px 14px; }

/* 动态动画 */
@keyframes shimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}
@keyframes glow {
  0%,100% { filter: drop-shadow(0 0 0 rgba(255,255,255,0)); }
  50% { filter: drop-shadow(0 0 3px rgba(255,255,255,0.25)); }
}
@keyframes orbit {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}
@keyframes pulseBorder {
  0%,100% { box-shadow: 0 0 0 0 rgba(59,130,246,0.0); }
  50% { box-shadow: 0 0 18px 4px rgba(59,130,246,0.25); }
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: .95; }
  95% { opacity: .6; }
  97% { opacity: .85; }
}
@keyframes sweep {
  0% { left: -40%; }
  100% { left: 140%; }
}
/* 动态脉冲与加冕动画 */
@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--pulse, rgba(59,130,246,0)); }
  50% { box-shadow: 0 0 18px 6px var(--pulse, rgba(59,130,246,0.28)); }
}
@keyframes crownPulse {
  0%, 100% { transform: translateZ(0) scale(1); }
  50% { transform: translateZ(0) scale(1.06); }
}

/* 五档样式：从“低调”到“酷炫”逐级增强 */

/* 1 档：墨痕初绽 - 青蓝清新（静态） */
.tier-1 .title-text {
  background-image: linear-gradient(90deg, #06b6d4, #3b82f6);
  background-size: 220% 100%;
  animation: shimmer 4s linear infinite;
}
.tier-1 { border-color: rgba(59,130,246,0.25); --pulse: rgba(59,130,246,0.22); animation: ringPulse 3.6s ease-in-out infinite; }
.tier-1::before {
  /* 轻微高光闪烁，偶尔一闪 */
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 999px;
  pointer-events: none;
  background: radial-gradient(circle at 60% 30%, rgba(255,255,255,0.15), transparent 60%);
  animation: flicker 6s ease-in-out infinite;
}

/* 2 档：玄疆漫步 - 金橙活力（轻微流动） */
.tier-2 .title-text {
  background-image: linear-gradient(90deg, #f59e0b, #f97316, #ef4444);
  background-size: 260% 100%;
  animation: shimmer 2s linear infinite;
}
.tier-2 { border-color: rgba(239, 68, 68, 0.25); --pulse: rgba(245,158,11,0.28); animation: ringPulse 3.0s ease-in-out infinite; }
.tier-2::before {
  content: '';
  position: absolute;
  left: -20%;
  top: 0;
  height: 100%;
  width: 35%;
  transform: skewX(-18deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
  pointer-events: none;
  animation: sweep 4.6s linear infinite;
}

/* 3 档：万象染境 - 紫粉梦幻（柔和发光 + 轻微流动） */
.tier-3 { animation: glow 2.2s ease-in-out infinite, ringPulse 2.8s ease-in-out infinite; --pulse: rgba(236,72,153,0.30); }
.tier-3 .title-text {
  background-image: linear-gradient(90deg, #a78bfa, #ec4899, #f43f5e);
  background-size: 300% 100%;
  animation: shimmer 1.8s linear infinite;
}
.tier-3 { border-color: rgba(236, 72, 153, 0.35); }
.tier-3::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 999px;
  pointer-events: none;
  background: radial-gradient(circle at 30% 50%, rgba(255,255,255,.22), transparent 50%), radial-gradient(circle at 70% 50%, rgba(255,255,255,.18), transparent 50%);
}
/* 额外扫光，提升可见的动态感 */
.tier-3::after {
  content: '';
  position: absolute;
  left: -30%;
  top: 0;
  width: 30%;
  height: 100%;
  transform: skewX(-15deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
  pointer-events: none;
  animation: sweep 3.2s linear infinite;
}

/* 4 档：永夜封疆 - 深蓝幽邃（星轨流动 + 环绕光点） */
.tier-4 .title-text {
  background-image: linear-gradient(90deg, #0ea5e9, #2563eb, #1d4ed8);
  background-size: 300% 100%;
  animation: shimmer 1.6s linear infinite;
}
.tier-4 { border-width: 2px; border-color: rgba(37, 99, 235, 0.45); --pulse: rgba(37,99,235,0.32); animation: ringPulse 2.4s ease-in-out infinite; }
.tier-4::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 999px;
  pointer-events: none;
  background:
    radial-gradient(circle at 30% 50%, rgba(255,255,255,0.18), transparent 40%),
    radial-gradient(circle at 70% 50%, rgba(255,255,255,0.12), transparent 40%);
  mix-blend-mode: screen;
}
.tier-4::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 140%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.6), transparent);
  transform-origin: center;
  border-radius: 999px;
  pointer-events: none;
  animation: orbit 6s linear infinite;
}

/* 在小尺寸徽章上关闭显眼的扫光/环绕线，避免看到“有条线在转” */
.size-sm.tier-4::after { display: none; }
.size-sm.tier-3::after { display: none; }

/* 全局关闭旋转/扫光线（任何尺寸）以保证干净视觉 */
.tier-4::after { display: none !important; }
.tier-4::before { display: none !important; }
.tier-3::after { display: none !important; }

/* 保险：小尺寸徽章完全关闭一切伪元素，避免任何扫光/线条外溢 */
.size-sm.title-badge::before,
.size-sm.title-badge::after { display: none !important; content: none !important; }

/* 5 档：无界墨尊 - 至尊虹彩（强发光 + 玻璃高光 + 粒子闪烁） */
.tier-5 {
  border-width: 2px;
  box-shadow: 0 10px 28px rgba(99,102,241,0.35), 0 0 18px 6px rgba(239,68,68,0.25);
  --pulse: rgba(239,68,68,0.40);
  animation: glow 1.8s ease-in-out infinite, ringPulse 2.2s ease-in-out infinite; /* 去掉放大动画 */
}
.tier-5 .title-text {
  background-image: linear-gradient(90deg, #22d3ee, #3b82f6, #a78bfa, #f472b6, #fb923c);
  background-size: 400% 100%;
  animation: shimmer 1.2s linear infinite;
}
.tier-5::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 999px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.28), rgba(255,255,255,0.06));
  mix-blend-mode: screen;
}
.tier-5::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  pointer-events: none;
  background:
    radial-gradient(6px 6px at 20% 40%, rgba(255,255,255,.6), transparent 60%),
    radial-gradient(4px 4px at 80% 30%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(5px 5px at 60% 70%, rgba(255,255,255,.45), transparent 60%),
    radial-gradient(3px 3px at 35% 75%, rgba(255,255,255,.5), transparent 60%);
  filter: blur(.3px);
  animation: shimmer 4.2s linear infinite;
}

/* —— 霓虹酷炫变体（模仿示例：红色刀锋霓虹） —— */
/* 霓虹公共骨架 */
.variant-neon { animation: flicker 3.6s ease-in-out infinite; }
.variant-neon::after {
  /* 斜向扫光效果 */
  content: '';
  position: absolute;
  top: 10%;
  left: -40%;
  width: 40%;
  height: 80%;
  transform: skewX(-15deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  filter: blur(0.3px);
  border-radius: 12px;
  pointer-events: none;
  animation: sweep 1.8s linear infinite;
}
.variant-neon::before {
  /* 中央发光横向光晕条，颜色由具体色系覆盖 */
  content: '';
  position: absolute;
  left: 6%;
  right: 6%;
  top: 50%;
  height: 60%;
  transform: translateY(-50%);
  border-radius: 999px;
  filter: blur(0.8px);
  pointer-events: none;
  opacity: .45;
}
.size-sm.variant-neon::before { opacity: .3; height: 50%; }
.size-sm.variant-neon::after { width: 30%; height: 70%; }
.size-sm.variant-neon .title-text { text-shadow: 0 0 1px rgba(255,255,255,.18), 0 0 3px rgba(255,255,255,.12); }

/* 1-4 档使用蓝/绿/紫/青霓虹，5 档为红霓虹 */
.variant-neon.neon-blue {
  border: 1px solid rgba(59,130,246,.55);
  background: linear-gradient(180deg, rgba(37,99,235,.10), rgba(59,130,246,.06));
  box-shadow: 0 4px 16px rgba(59,130,246,.22), inset 0 0 6px rgba(59,130,246,.18);
}
.variant-neon.neon-blue .title-text {
  background-image: linear-gradient(90deg, #bfdbfe, #60a5fa, #3b82f6, #93c5fd);
  text-shadow: 0 0 2px rgba(59,130,246,.35), 0 0 6px rgba(59,130,246,.25);
}
.variant-neon.neon-blue::before { background: radial-gradient(ellipse at center, rgba(59,130,246,.45), rgba(59,130,246,.10) 60%, transparent 70%); }

.variant-neon.neon-green {
  border: 1px solid rgba(16,185,129,.55);
  background: linear-gradient(180deg, rgba(5,150,105,.12), rgba(16,185,129,.06));
  box-shadow: 0 4px 16px rgba(16,185,129,.22), inset 0 0 6px rgba(16,185,129,.18);
}
.variant-neon.neon-green .title-text {
  background-image: linear-gradient(90deg, #d1fae5, #6ee7b7, #10b981, #a7f3d0);
  text-shadow: 0 0 2px rgba(16,185,129,.35), 0 0 6px rgba(16,185,129,.2);
}
.variant-neon.neon-green::before { background: radial-gradient(ellipse at center, rgba(16,185,129,.45), rgba(16,185,129,.10) 60%, transparent 70%); }

.variant-neon.neon-purple {
  border: 1px solid rgba(168,85,247,.55);
  background: linear-gradient(180deg, rgba(147,51,234,.12), rgba(168,85,247,.06));
  box-shadow: 0 4px 16px rgba(168,85,247,.22), inset 0 0 6px rgba(168,85,247,.18);
}
.variant-neon.neon-purple .title-text {
  background-image: linear-gradient(90deg, #e9d5ff, #c084fc, #a855f7, #ddd6fe);
  text-shadow: 0 0 2px rgba(168,85,247,.35), 0 0 6px rgba(168,85,247,.22);
}
.variant-neon.neon-purple::before { background: radial-gradient(ellipse at center, rgba(168,85,247,.45), rgba(168,85,247,.10) 60%, transparent 70%); }

.variant-neon.neon-cyan {
  border: 1px solid rgba(6,182,212,.55);
  background: linear-gradient(180deg, rgba(6,182,212,.12), rgba(34,211,238,.06));
  box-shadow: 0 4px 16px rgba(34,211,238,.22), inset 0 0 6px rgba(34,211,238,.18);
}
.variant-neon.neon-cyan .title-text {
  background-image: linear-gradient(90deg, #cffafe, #67e8f9, #22d3ee, #a5f3fc);
  text-shadow: 0 0 2px rgba(34,211,238,.35), 0 0 6px rgba(34,211,238,.22);
}
.variant-neon.neon-cyan::before { background: radial-gradient(ellipse at center, rgba(34,211,238,.45), rgba(34,211,238,.10) 60%, transparent 70%); }

.variant-neon.neon-red {
  border: 1px solid rgba(255, 77, 79, 0.55);
  background: linear-gradient(180deg, rgba(255, 0, 0, 0.08), rgba(255, 0, 0, 0.04));
  box-shadow: 0 4px 16px rgba(255, 0, 64, 0.22), inset 0 0 6px rgba(255, 0, 64, 0.18);
}
.variant-neon.neon-red .title-text {
  background-image: linear-gradient(90deg, #ffc0cb, #ff5a5a, #ff1f1f, #ffd6d6);
  text-shadow: 0 0 2px rgba(255, 74, 74, .35), 0 0 6px rgba(255, 74, 74, .22);
}
.variant-neon.neon-red::before { background: radial-gradient(ellipse at center, rgba(255, 76, 76, 0.45), rgba(255, 76, 76, 0.10) 60%, transparent 70%); }

/* 极光虹彩变体（备用，可与默认五档对比） */
.variant-aurora {
  border: 1px solid rgba(99,102,241, .45);
  background: linear-gradient(180deg, rgba(34,211,238,0.08), rgba(59,130,246,0.06));
}
.variant-aurora .title-text {
  background-image: linear-gradient(90deg, #22d3ee, #3b82f6, #a78bfa, #f472b6, #fb923c);
  background-size: 260% 100%;
  animation: shimmer 2.6s linear infinite;
}
</style>


